package com.xmwzw.catpu.viewmodel;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.text.TextUtils;
import android.util.Log;

import com.xmwzw.catpu.validator.PhoneValidator;
import com.xmwzw.catpu.validator.RangeValidator;

/**
 * @author : wangzw
 * @date : 20-4-1下午7:32
 * @desc :
 */
public class RegisterViewModel extends BaseObservable {
    private PhoneValidator phoneValidator = new PhoneValidator("");
    private RangeValidator passwordValidator = new RangeValidator("", 6, 20);

    @Bindable
    public String mAccount = "";

    @Bindable
    public String mPassword ="";

    @Bindable
    public String mConfirmPaw = "";

    @Bindable
    public String getValidateError() {
        Log.d("", "getValidateError: "+mAccount+"---"+mPassword);
        String error = "";
        if (TextUtils.isEmpty(mAccount) || !phoneValidator.isValid(mAccount)) {
            error = "请填写有效的手机号";
        } else if (TextUtils.isEmpty(mPassword) || !passwordValidator.isValid(mPassword)) {
            error = "请填写有效的密码";
        }  else if (!mConfirmPaw.equals(mPassword)) {
            error = "两次输入的密码不一致";
        }
        return error;
    }
}